package org.hit.burkun.entities.realtions;

import org.hit.burkun.db.DBTypeConverter.DATATYPE;

public class BaseRealtionDBConfigure {
	// dump to db
	public static String[] dumpDBArray(BaseRealtion br) {
		// Aacc, Bacc, Aname, Bname, score if any, method if any ,direction if
		// any, direction_proper, category of relationship, category of A,
		// category of B
		// renew1 ent1_pid, ent2_pid, score, score_method, isdirect, rel_desc,
		// rel_type, ent1_type, ent2_type
		// renew2 primary_id, ent1_pid, ent2_pid, score, score_method, isdirect,
		// rel_desc, rel_type, ent1_type, ent2_type, evidence_urls, other_data
		String[] res = new String[15]; // 主键不写入
		res[0] = br.getEnt1().getPrimary_id(); // 记录的是entity在index_term中的id
		res[1] = br.getEnt2().getPrimary_id(); // 纪录的是entity在index_term中的id
		res[2] = br.getEnt1().getDbid();
		res[3] = br.getEnt2().getDbid();
		res[4] = br.getEnt1().getName();
		res[5] = br.getEnt2().getName();
		res[6] = br.getConfidscore() == null ? null : String.valueOf(br
				.getConfidscore());
		res[7] = br.getCalcMethod() == null ? null : br.getCalcMethod();
		res[8] = br.isDirect() ? "1" : "0";
		res[9] = br.getDesc();
		res[10] = br.getType().getTag();
		res[11] = br.getEnt1().getType().getTag();
		res[12] = br.getEnt2().getType().getTag();
		res[13] = br.getEvidenceUrls();
		if (br.getOtherData() != null) {
			res[14] = br.getOtherData().toString();
		}
		return res;
	}

	// dump inverse rel to db
	public static String[] dumpReverseDBArray(BaseRealtion br) {
		// Aacc, Bacc, Aname, Bname, score if any, method if any ,direction if
		// any, direction_proper, category of relationship, category of A,
		// category of B
		// renew ent1_pid, ent2_pid, score, score_method, isdirect, rel_desc,
		// rel_type, ent1_type, ent2_type
		// renew2 ent1_pid, ent2_pid, score, score_method, isdirect, rel_desc,
		// rel_type, ent1_type, ent2_type, evidence_urls, other_data
		String[] res = new String[15]; // 主键不写入
		res[0] = br.getEnt2().getPrimary_id(); // 记录的是entity在index_term中的id
		res[1] = br.getEnt1().getPrimary_id(); // 纪录的是entity在index_term中的id
		res[3] = br.getEnt1().getDbid();
		res[2] = br.getEnt2().getDbid();
		res[5] = br.getEnt1().getName();
		res[4] = br.getEnt2().getName();
		res[6] = br.getConfidscore() == null ? null : String.valueOf(br
				.getConfidscore());
		res[7] = br.getCalcMethod() == null ? null : br.getCalcMethod();
		res[8] = br.isDirect() ? "1" : "0";
		res[9] = br.getDesc();
		res[10] = br.getType().getReverseTag();
		res[11] = br.getEnt2().getType().getTag();
		res[12] = br.getEnt1().getType().getTag();
		res[13] = br.getEvidenceUrls();
		if (br.getOtherData() != null) {
			res[14] = br.getOtherData().toString();
		}
		return res;
	}

	public static DATATYPE[] getDbDataTypes() {
		int offset = 1;
		DATATYPE[] types = new DATATYPE[15 + offset];
		types[0] = DATATYPE.I;
		types[1] = DATATYPE.I;
		types[2] = DATATYPE.I;
		types[6 + offset] = DATATYPE.D;
		types[8 + offset] = DATATYPE.I;
		return types;
	}

	public static DATATYPE[] getDbDataTypesWithoutPid() {
		DATATYPE[] types = new DATATYPE[15];
		types[0] = DATATYPE.I;
		types[1] = DATATYPE.I;
		types[6] = DATATYPE.D;
		types[8] = DATATYPE.I;
		return types;
	}

	private static String[] fileds = new String[] { "ent1_pid", "ent2_pid",
			"ent1_dbid", "ent2_dbid", "ent1_name", "ent2_name", "score",
			"score_method", "isdirect", "rel_desc", "rel_type", "ent1_type",
			"ent2_type", "evidence_urls", "other_data" };

	public static String[] getFields() {
		return fileds;
	}
}
